//
//  MSSetRoomManagementController.m
//  觅尚
//
//  Created by No.8 on 2019/4/11.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSSetRoomManagementController.h"
#import "MSRoomConsumOtionCell.h"
#import "MSOperationButton.h"
#import "MSSetRoomManagementCell.h"
#import "MSWaiterListController.h"
#import "MSReservationsListController.h"
#import "MSRoomHousesListController.h"

@interface MSSetRoomManagementController ()<UITableViewDataSource,UITableViewDelegate,UITextViewDelegate,MSWaiterListVCDelegate,MSReservationsListVCDelegate,MSRoomHousesListVCDelegate>
{
    CustomNavigationBar *naviagtionBar;
}
/** 表视图*/
@property(nonatomic,strong)UITableView *tableView;

/** 选择按钮*/
@property(nonatomic,strong)UIButton *selectedButton;


/** 订房人按钮*/
@property(nonatomic,strong)UIButton *ReservationsButton;


/** 服务员按钮*/
@property(nonatomic,strong)UIButton *WaiterButton;

/** 底部所有的标签 */
@property (nonatomic, strong) UIView  * titlesView;


/** uid*/
@property(nonatomic,strong)NSString *uidStr;

/** 订房人id*/
@property(nonatomic,strong)NSString *ReservationsuidStr;

/** 头像*/
@property(nonatomic,strong)NSString *PhotoStr;

/** 订房人昵称*/
@property(nonatomic,strong)UILabel * NameLabel;


/** 订房人头像*/
@property(nonatomic,strong)UIImageView * NameIMG;


/** 服务员昵称*/
@property(nonatomic,strong)UILabel * WaiterNameLabel;


/** 服务员头像*/
@property(nonatomic,strong)UIImageView * WaiterNameIMG;

/** 确定按钮*/
@property(nonatomic,strong)UIButton * DetermineButton;


/** 房间号*/
@property(nonatomic,strong)UILabel *showtitlelabel;


/** 房间号*/
@property(nonatomic,strong)UIButton *showtitleButton;

/** 更换房间id*/
@property(nonatomic,strong)NSString *replaceRoomID;

/** 更换房间名称*/
@property(nonatomic,strong)NSString *replaceRoomName;
@end

@implementation MSSetRoomManagementController

- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    WYCLog(@"self.roomName----------%@",self.roomName);
    
    
    [self CreateNavigationBar];
    
    
    [self CreatView];
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        [self tableView];
        
    });
    
   
    
}
- (void)CreatView{
    UIView * HeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, [self navBarBottom], ScreenWidth, 200 * px)];
    HeaderView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:HeaderView];
    
    /** title*/
    UILabel * showtitlelabel = [[UILabel alloc] initWithFrame:CGRectMake(20 * px, 20 * px, HeaderView.width, 60 * px)];
    showtitlelabel.textColor = [UIColor whiteColor];
    showtitlelabel.text = [NSString stringWithFormat:@"请选择您要对房间%@进行的操作:",self.roomName];
    showtitlelabel.textAlignment = NSTextAlignmentLeft;
    showtitlelabel.font = [UIFont systemFontOfSize:SYRealValue(35 / 2)];
    [HeaderView addSubview:showtitlelabel];
    self.showtitlelabel = showtitlelabel;
    
    
    UIView * operationView = [[UIView alloc] initWithFrame:CGRectMake(90 * px, CGRectGetMaxY(showtitlelabel.frame) + 50 * px, HeaderView.width - 180 * px, 100 * px)];
    operationView.backgroundColor = [UIColor clearColor];
    [HeaderView addSubview:operationView];
    
    
    UIView * lineView = [[UIView alloc] initWithFrame:CGRectMake(0, HeaderView.height - 1, HeaderView.width, 1)];
    lineView.backgroundColor = BackViewColor;
    [HeaderView addSubview:lineView];
    
    
    
    
    /** 确定*/
    UIButton * DetermineButton = [[UIButton alloc] initWithFrame:CGRectMake(100 * px, ScreenHeight - 620 * px, ScreenWidth - 200 * px, 120 * px)];
    [DetermineButton setBackgroundImage:[UIImage imageNamed:@"底部按钮背景"] forState:UIControlStateNormal];
    [DetermineButton setTitle:@"确定" forState:UIControlStateNormal];
    DetermineButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
    DetermineButton.layer.cornerRadius = 60 * px;
    DetermineButton.layer.masksToBounds = YES;
    [DetermineButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [DetermineButton addTarget:self action:@selector(DetermineButtonClick) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:DetermineButton];
    self.DetermineButton = DetermineButton;
    
    
}

- (void)ButtonClick:(UIButton *)button{
    //修改按钮状态
    self.selectedButton.enabled = YES;
    button.enabled = NO;
    self.selectedButton = button;
    
}
/** 表视图*/
- (UITableView *)tableView{
    self.extendedLayoutIncludesOpaqueBars = YES;
    if (!_tableView) {
        
        if (@available(iOS 11.0, *)) {
            
            _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
        } else {
            
            self.automaticallyAdjustsScrollViewInsets = NO;
            
        }
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, [self navBarBottom] + 200 * px, ScreenWidth, 840 * px) style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor clearColor];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
//        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.separatorColor = BackViewColor;
        _tableView.scrollEnabled = NO;
        [self.view addSubview:self.tableView];
    }
    return _tableView;
}


- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"房间管理";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    WYCLog(@"self.tagStr----%@",self.tagStr);
    if ([self.tagStr isEqualToString:@"换房"]) {
        return 4;
    }else{
        return 3;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 2) {
        
        return 280 * px;
    }else{
        return 140 * px;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    MSSetRoomManagementCell * cell = [MSSetRoomManagementCell cellWithTableView:tableView];
    tableView.backgroundColor = [UIColor clearColor];
    //无色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    //    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    if (![self.tagStr isEqualToString:@"换房"]) {
        if (indexPath.row == 0) {
            cell.TimeLabel.text = @"订房人";
            
            
            /** 日历按钮*/
            UIImageView * NameIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(cell.TimeLabel.frame) + 50 * px, 20 * px, 100 * px, 100 * px)];
            NameIMG.layer.cornerRadius = 50 * px;
            NameIMG.layer.masksToBounds = YES;
            NameIMG.backgroundColor = BackViewColor;
            if (self.RPhoto == nil || self.RPhoto == NULL || [self.RPhoto isKindOfClass:[NSNull class]] || [[self.RPhoto stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                NameIMG.image = [UIImage imageNamed:@""];
            }else{
                [NameIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.RPhoto]]];
            }
            //        NameIMG.image = [UIImage imageNamed:@"daka_bg"];
            [cell.contentView addSubview:NameIMG];
            self.NameIMG = NameIMG;
            
            /** 昵称*/
            UILabel * NameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(NameIMG.frame) + 20 * px, cell.TimeLabel.y, cell.TimeLabel.width, cell.TimeLabel.height)];
            NameLabel.textColor = cell.TimeLabel.textColor;
            if (self.RName == nil || self.RName == NULL || [self.RName isKindOfClass:[NSNull class]] || [[self.RName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                NameLabel.text = @"昵称";
            }else{
                NameLabel.text = [NSString stringWithFormat:@"%@",self.RName];
            }
            
            NameLabel.textAlignment = NSTextAlignmentLeft;
            NameLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:NameLabel];
            self.NameLabel = NameLabel;
            
            
            
            /** 添加*/
            UIButton * addButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 210 * px, NameLabel.y, 150 * px, NameLabel.height)];
            if (self.RID == nil || self.RID == NULL || [self.RID isKindOfClass:[NSNull class]] || [[self.RID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                [addButton setTitle:@"添加" forState:UIControlStateNormal];
                //设置边框颜色
                addButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
                [addButton setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
                //            addButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
                addButton.layer.borderWidth = 1.0f;
                
            }else{
                [addButton setTitle:@"删除" forState:UIControlStateNormal];
                [addButton setTitleColor:WYCRGBColor(220, 75, 108) forState:UIControlStateNormal];
                addButton.layer.borderColor = WYCRGBColor(220, 75, 108).CGColor;
                //设置边框宽度
                addButton.layer.borderWidth = 1.0f;
            }
            
            
            //给按钮设置角的弧度
            addButton.layer.cornerRadius = 30 * px;
            addButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            //        [addButton setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
            [addButton addTarget:self action:@selector(ReservationsButtonclick:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView  addSubview:addButton];
            self.ReservationsButton = addButton;
            
            
        }else if (indexPath.row == 1) {
            cell.TimeLabel.text = @"服务员";
            /** 日历按钮*/
            UIImageView * NameIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(cell.TimeLabel.frame) + 50 * px, 20 * px, 100 * px, 100 * px)];
            NameIMG.layer.cornerRadius = 50 * px;
            NameIMG.layer.masksToBounds = YES;
            NameIMG.backgroundColor = BackViewColor;
            if (self.WPhoto == nil || self.WPhoto == NULL || [self.WPhoto isKindOfClass:[NSNull class]] || [[self.WPhoto stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                NameIMG.image = [UIImage imageNamed:@""];
            }else{
                [NameIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.WPhoto]]];
            }
            //        NameIMG.image = [UIImage imageNamed:@"daka_bg"];
            [cell.contentView addSubview:NameIMG];
            self.WaiterNameIMG = NameIMG;
            
            /** 昵称*/
            UILabel * NameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(NameIMG.frame) + 20 * px, cell.TimeLabel.y, cell.TimeLabel.width, cell.TimeLabel.height)];
            NameLabel.textColor = cell.TimeLabel.textColor;
            if (self.WName == nil || self.WName == NULL || [self.WName isKindOfClass:[NSNull class]] || [[self.WName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                NameLabel.text = @"昵称";
            }else{
                NameLabel.text = [NSString stringWithFormat:@"%@",self.WName];
            }
            NameLabel.textAlignment = NSTextAlignmentLeft;
            NameLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:NameLabel];
            self.WaiterNameLabel = NameLabel;
            
            /** 添加*/
            UIButton * WaiterButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 210 * px, NameLabel.y, 150 * px, NameLabel.height)];
            if (self.WID == nil || self.WID == NULL || [self.WID isKindOfClass:[NSNull class]] || [[self.WID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                [WaiterButton setTitle:@"添加" forState:UIControlStateNormal];
                WaiterButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
                [WaiterButton setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
                //            addButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
                WaiterButton.layer.borderWidth = 1.0f;
            }else{
                [WaiterButton setTitle:@"删除" forState:UIControlStateNormal];
                [WaiterButton setTitleColor:WYCRGBColor(220, 75, 108) forState:UIControlStateNormal];
                WaiterButton.layer.borderColor =  WYCRGBColor(220, 75, 108).CGColor;
                //设置边框宽度
                WaiterButton.layer.borderWidth = 1.0f;
                
            }
            
            //设置边框颜色
            //        WaiterButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
            //设置边框宽度
            //        WaiterButton.layer.borderWidth = 1.0f;
            //给按钮设置角的弧度
            WaiterButton.layer.cornerRadius = 30 * px;
            WaiterButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            //        [WaiterButton  setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
            //        if ([self.ReservationsButton.titleLabel.text isEqualToString:@"添加"]) {
            //            [MBManager showBriefAlert:@"请先添加订房人"];
            //        }else{
            [WaiterButton  addTarget:self action:@selector(WaiterButton:) forControlEvents:UIControlEventTouchUpInside];
            //        }
            
            [cell.contentView  addSubview:WaiterButton];
            self.WaiterButton = WaiterButton;
        }else{
            //        cell.TimeLabel.text = @"服务员";
            UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(20 * px, 0, ScreenWidth - 40 * px, 280 * px)];
            textView.backgroundColor = [UIColor clearColor];
            //文本
            textView.text = @"备注:添加后展示头像和昵称";
            //字体
            textView.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            //对齐
            textView.textAlignment = NSTextAlignmentCenter;
            //字体颜色
            textView.textColor = BackViewColor;
            //允许编辑
            textView.editable = YES;
            //用户交互     ///////若想有滚动条 不能交互 上为No，下为Yes
            textView.userInteractionEnabled = NO;
            textView.delegate = self;
            [cell.contentView addSubview:textView];
            
        }
    }else{
        if (indexPath.row == 0) {
            cell.TimeLabel.text = @"订房人";
            
            
            /** 日历按钮*/
            UIImageView * NameIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(cell.TimeLabel.frame) + 50 * px, 20 * px, 100 * px, 100 * px)];
            NameIMG.layer.cornerRadius = 50 * px;
            NameIMG.layer.masksToBounds = YES;
            NameIMG.backgroundColor = BackViewColor;
            if (self.RPhoto == nil || self.RPhoto == NULL || [self.RPhoto isKindOfClass:[NSNull class]] || [[self.RPhoto stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                NameIMG.image = [UIImage imageNamed:@""];
            }else{
                [NameIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.RPhoto]]];
            }
            //        NameIMG.image = [UIImage imageNamed:@"daka_bg"];
            [cell.contentView addSubview:NameIMG];
            self.NameIMG = NameIMG;
            
            /** 昵称*/
            UILabel * NameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(NameIMG.frame) + 20 * px, cell.TimeLabel.y, cell.TimeLabel.width, cell.TimeLabel.height)];
            NameLabel.textColor = cell.TimeLabel.textColor;
            if (self.RName == nil || self.RName == NULL || [self.RName isKindOfClass:[NSNull class]] || [[self.RName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                NameLabel.text = @"昵称";
            }else{
                NameLabel.text = [NSString stringWithFormat:@"%@",self.RName];
            }
            
            NameLabel.textAlignment = NSTextAlignmentLeft;
            NameLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:NameLabel];
            self.NameLabel = NameLabel;
            
            
            
            /** 添加*/
            UIButton * addButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 210 * px, NameLabel.y, 150 * px, NameLabel.height)];
            if (self.RID == nil || self.RID == NULL || [self.RID isKindOfClass:[NSNull class]] || [[self.RID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                [addButton setTitle:@"添加" forState:UIControlStateNormal];
                //设置边框颜色
                addButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
                [addButton setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
                //            addButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
                addButton.layer.borderWidth = 1.0f;
                
            }else{
                [addButton setTitle:@"删除" forState:UIControlStateNormal];
                [addButton setTitleColor:WYCRGBColor(220, 75, 108) forState:UIControlStateNormal];
                addButton.layer.borderColor = WYCRGBColor(220, 75, 108).CGColor;
                //设置边框宽度
                addButton.layer.borderWidth = 1.0f;
            }
            
            
            //给按钮设置角的弧度
            addButton.layer.cornerRadius = 30 * px;
            addButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            //        [addButton setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
            [addButton addTarget:self action:@selector(ReservationsButtonclick:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView  addSubview:addButton];
            self.ReservationsButton = addButton;
            
            
        }else if (indexPath.row == 1) {
            cell.TimeLabel.text = @"服务员";
            /** 日历按钮*/
            UIImageView * NameIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(cell.TimeLabel.frame) + 50 * px, 20 * px, 100 * px, 100 * px)];
            NameIMG.layer.cornerRadius = 50 * px;
            NameIMG.layer.masksToBounds = YES;
            NameIMG.backgroundColor = BackViewColor;
            if (self.WPhoto == nil || self.WPhoto == NULL || [self.WPhoto isKindOfClass:[NSNull class]] || [[self.WPhoto stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                NameIMG.image = [UIImage imageNamed:@""];
            }else{
                [NameIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.WPhoto]]];
            }
            //        NameIMG.image = [UIImage imageNamed:@"daka_bg"];
            [cell.contentView addSubview:NameIMG];
            self.WaiterNameIMG = NameIMG;
            
            /** 昵称*/
            UILabel * NameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(NameIMG.frame) + 20 * px, cell.TimeLabel.y, cell.TimeLabel.width, cell.TimeLabel.height)];
            NameLabel.textColor = cell.TimeLabel.textColor;
            if (self.WName == nil || self.WName == NULL || [self.WName isKindOfClass:[NSNull class]] || [[self.WName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                NameLabel.text = @"昵称";
            }else{
                NameLabel.text = [NSString stringWithFormat:@"%@",self.WName];
            }
            NameLabel.textAlignment = NSTextAlignmentLeft;
            NameLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:NameLabel];
            self.WaiterNameLabel = NameLabel;
            
            /** 添加*/
            UIButton * WaiterButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth - 210 * px, NameLabel.y, 150 * px, NameLabel.height)];
            if (self.WID == nil || self.WID == NULL || [self.WID isKindOfClass:[NSNull class]] || [[self.WID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0){
                [WaiterButton setTitle:@"添加" forState:UIControlStateNormal];
                WaiterButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
                [WaiterButton setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
                //            addButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
                WaiterButton.layer.borderWidth = 1.0f;
            }else{
                [WaiterButton setTitle:@"删除" forState:UIControlStateNormal];
                [WaiterButton setTitleColor:WYCRGBColor(220, 75, 108) forState:UIControlStateNormal];
                WaiterButton.layer.borderColor =  WYCRGBColor(220, 75, 108).CGColor;
                //设置边框宽度
                WaiterButton.layer.borderWidth = 1.0f;
                
            }
            
            //设置边框颜色
            //        WaiterButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
            //设置边框宽度
            //        WaiterButton.layer.borderWidth = 1.0f;
            //给按钮设置角的弧度
            WaiterButton.layer.cornerRadius = 30 * px;
            WaiterButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            //        [WaiterButton  setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
            //        if ([self.ReservationsButton.titleLabel.text isEqualToString:@"添加"]) {
            //            [MBManager showBriefAlert:@"请先添加订房人"];
            //        }else{
            [WaiterButton  addTarget:self action:@selector(WaiterButton:) forControlEvents:UIControlEventTouchUpInside];
            //        }
            
            [cell.contentView  addSubview:WaiterButton];
            self.WaiterButton = WaiterButton;
        }else if (indexPath.row == 2) {
            //        cell.TimeLabel.text = @"服务员";
            UITextView* textView = [[UITextView alloc] initWithFrame:CGRectMake(20 * px, 0, ScreenWidth - 40 * px, 280 * px)];
            textView.backgroundColor = [UIColor clearColor];
            //文本
            textView.text = @"备注:添加后展示头像和昵称";
            //字体
            textView.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            //对齐
            textView.textAlignment = NSTextAlignmentCenter;
            //字体颜色
            textView.textColor = BackViewColor;
            //允许编辑
            textView.editable = YES;
            //用户交互     ///////若想有滚动条 不能交互 上为No，下为Yes
            textView.userInteractionEnabled = NO;
            textView.delegate = self;
            [cell.contentView addSubview:textView];
            
        }else{
            cell.TimeLabel.text = @"更换房间";
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            UILabel * genghuaLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenWidth - 300 * px, cell.TimeLabel.y, cell.TimeLabel.width, cell.TimeLabel.height)];
            genghuaLabel.textColor = cell.TimeLabel.textColor;
            genghuaLabel.text = [NSString stringWithFormat:@"%@",self.roomName];
            
            WYCLog(@"更换房间%@",self.roomName);
            genghuaLabel.textAlignment = NSTextAlignmentRight;
            genghuaLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
            [cell.contentView addSubview:genghuaLabel];
//            self.WaiterNameLabel = NameLabel;
            
        }
    }
    return cell;
}
- (void)ClickreplaceButtonRoomID:(NSString *)RoomID RoomName:(NSString *)RoomName{
    
    [self.tableView reloadData];
    self.Newroomid = RoomID;
//    WYCLog(@"=========%@",RoomName);
//    [self.showtitleButton setTitle:RoomName forState:UIControlStateNormal];
    self.roomName = RoomName;
    
//    WYCLog(@"=========%@",self.self.roomid);
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 3) {
        MSRoomHousesListController * ListVC = [[MSRoomHousesListController alloc] init];
        ListVC.RID = self.RID;
        ListVC.WID = self.WID;
        ListVC.Roomid = self.roomid;
        ListVC.replaceButtonDelegate = self;
        [self.navigationController pushViewController:ListVC animated:NO];
    }
}
- (void)ReservationsButtonclick:(UIButton *)button{
//    [self.tableView reloadData];
//    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:1 inSection:0];
//    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    if ([button.titleLabel.text isEqualToString:@"添加"]) {
        MSReservationsListController * WaiterListVC = [[MSReservationsListController alloc] init];
        WaiterListVC.AddInversepassvalueDelegate = self;
        WaiterListVC.roomid = self.roomid;
        [self.navigationController pushViewController:WaiterListVC animated:NO];
    }else if ([button.titleLabel.text isEqualToString:@"删除"]) {
        self.NameIMG.image = [UIImage imageNamed:@""];
        self.NameIMG.backgroundColor = BackViewColor;
        self.NameLabel.text = @"昵称";
        [button setTitle:@"添加" forState:UIControlStateNormal];
        button.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
        [button setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
    }
    
    
}

- (void)WaiterButton:(UIButton *)sender{
//    [self.tableView reloadData];
//    NSIndexPath *indexPath=[NSIndexPath indexPathForRow:2 inSection:0];
//    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
    if ([sender.titleLabel.text isEqualToString:@"添加"]) {
        MSWaiterListController * WaiterListVC = [[MSWaiterListController alloc] init];
        WaiterListVC.AddInversepassvalueDelegate = self;
        WaiterListVC.roomid = self.roomid;
        [self.navigationController pushViewController:WaiterListVC animated:NO];
    }else if ([sender.titleLabel.text isEqualToString:@"删除"]){
        self.WaiterNameIMG.image = [UIImage imageNamed:@""];
        self.WaiterNameIMG.backgroundColor = BackViewColor;
        self.WaiterNameLabel.text = @"昵称";
        [sender setTitle:@"添加" forState:UIControlStateNormal];
        sender.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
        [sender setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
    }
    
}


//订房人传值
- (void)Reservationsvalue:(NSString *)NameStrValue PhotoStr:(NSString *)PhotoStrStrValue UidStrValue:(NSString *)UidStrValue{
//    [self.tableView reloadData];
//    WYCLog(@"------%@",UidStrValue);
    if (![self.RID isEqualToString:@""]) {
        [self.ReservationsButton setTitle:@"删除" forState:UIControlStateNormal];
        self.ReservationsButton.layer.borderColor = WYCRGBColor(220, 75, 108).CGColor;
        [self.ReservationsButton setTitleColor:WYCRGBColor(220, 75, 108) forState:UIControlStateNormal];
    }else{
        [self.ReservationsButton setTitle:@"添加" forState:UIControlStateNormal];
        self.ReservationsButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
        [self.ReservationsButton setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
        
    }
    [self.NameIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",PhotoStrStrValue]]];
    self.NameLabel.text = [NSString stringWithFormat:@"%@",NameStrValue];
    self.RID = UidStrValue;
}


//服务员传值
- (void)Inversepassvalue:(NSString *)NameStrValue PhotoStr:(NSString *)PhotoStrStrValue UidStrValue:(NSString *)UidStrValue{
    if (![self.WID isEqualToString:@""]) {
        [self.WaiterButton setTitle:@"删除" forState:UIControlStateNormal];
        self.WaiterButton.layer.borderColor = WYCRGBColor(220, 75, 108).CGColor;
        [self.WaiterButton setTitleColor:WYCRGBColor(220, 75, 108) forState:UIControlStateNormal];
    }else{
        [self.WaiterButton setTitle:@"添加" forState:UIControlStateNormal];
        self.WaiterButton.layer.borderColor = WYCRGBColor(57, 119, 213).CGColor;
        [self.WaiterButton setTitleColor:WYCRGBColor(57, 119, 213) forState:UIControlStateNormal];
        
    }
    self.WID = UidStrValue;
    [self.WaiterNameIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",PhotoStrStrValue]]];
    self.WaiterNameLabel.text = [NSString stringWithFormat:@"%@",NameStrValue];
    
    
}


//确定按钮
- (void)DetermineButtonClick{
//    WYCLog(@"----------%@",self.uidStr);
    
    if ([self.tagStr isEqualToString:@"换房"]) {
        if ([self.Newroomid isEqualToString:self.roomid]) {
            [MBManager showBriefAlert:@"请修改房间"];
            return;
        }
        if ([self.NameLabel.text isEqualToString:@"昵称"]) {
            [MBManager showBriefAlert:@"请选择订房人"];
            return;
        }
        
        NSString * roomStateStr = @"";
        if ([self.tagStr isEqualToString:@"开房"]) {
            roomStateStr = @"1";
        }else if ([self.tagStr isEqualToString:@"预约"]){
            roomStateStr = @"2";
        }else {
            roomStateStr = @"5";
        }
        NSString * uidstr = @"";
        if (self.WID.length != 0) {
            uidstr = self.WID;
        }else{
            uidstr = @"";
        }
        if ([roomStateStr isEqualToString:@"1"]) {
            if ([self.WaiterNameLabel.text isEqualToString:@"昵称"]) {
                [MBManager showBriefAlert:@"请选择服务员"];
                return;
            }
        }
        
        NSDictionary * params = @{@"roomId":self.roomid,@"waiterUid":uidstr,@"openRoomUid":self.RID,@"roomState":roomStateStr,@"changeRoomId":self.Newroomid};
        //    NSMutableDictionary * params = [NSMutableDictionary dictionary];
        //    pa
        WYCLog(@"----------%@",params);
        [HTTPRequest POST:MSupdateRoomState params:params succeed:^(id responseObject) {
            
            WYCLog(@"----------%@",responseObject);
            if (CodeStr) {
                [MBManager showBriefAlert:responseObject[@"msg"]];
                [self.navigationController popViewControllerAnimated:NO];
            }else{
                [MBManager showBriefAlert:responseObject[@"msg"]];
            }
        } failure:^(NSError *error) {
            [MBManager showBriefAlert:Failed];
        }];
    }else{
       
        if ([self.NameLabel.text isEqualToString:@"昵称"]) {
            [MBManager showBriefAlert:@"请选择订房人"];
            return;
        }
        
        NSString * roomStateStr = @"";
        if ([self.tagStr isEqualToString:@"开房"]) {
            roomStateStr = @"1";
        }else if ([self.tagStr isEqualToString:@"预约"]){
            roomStateStr = @"2";
        }else {
            roomStateStr = @"5";
        }
        NSString * uidstr = @"";
        if (self.WID.length != 0) {
            uidstr = self.WID;
        }else{
            uidstr = @"";
        }
        if ([roomStateStr isEqualToString:@"1"]) {
            if ([self.WaiterNameLabel.text isEqualToString:@"昵称"]) {
                [MBManager showBriefAlert:@"请选择服务员"];
                return;
            }
        }
        
        NSDictionary * params = @{@"roomId":self.roomid,@"waiterUid":uidstr,@"openRoomUid":self.RID,@"roomState":roomStateStr,@"changeRoomId":@0};
        //    NSMutableDictionary * params = [NSMutableDictionary dictionary];
        //    pa
        WYCLog(@"----------%@",params);
        [HTTPRequest POST:MSupdateRoomState params:params succeed:^(id responseObject) {
            
            WYCLog(@"----------%@",responseObject);
            if (CodeStr) {
                [MBManager showBriefAlert:responseObject[@"msg"]];
                [self.navigationController popViewControllerAnimated:NO];
            }else{
                [MBManager showBriefAlert:responseObject[@"msg"]];
            }
        } failure:^(NSError *error) {
            [MBManager showBriefAlert:Failed];
        }];
    }
    
    
    
    
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}
@end
